﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

namespace HQWeb.SysManage.DictionaryManage
{
    public partial class DictionaryAddChild : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            VerdictIsLogin();
            if (!IsPostBack)
            {
                BindType();
            }
        }

        #region 绑定所属类型
        protected void BindType()
        {
            BLL.SysManage.T_PUB_DICTIONARY bll = new BLL.SysManage.T_PUB_DICTIONARY();
            string str = " FLAG = 1 and PARENT_ID = 0 ";
            IList il = bll.GetModelList(str);
            ddl_type.ClearSelection();
            ddl_type.DataSource = il;
            ddl_type.DataTextField = "NAME"; //dropdownlist的Text的字段 
            ddl_type.DataValueField = "ID";//dropdownlist的Value的字段 
            ddl_type.DataBind();
            ddl_type.SelectedValue = Request.QueryString["ID"];
            //ListItem item = new ListItem("", "0");
            //item.Selected = true;
            //ddl_type.Items.Add(item);
        }
        #endregion


        #region  添加用户组
        protected void btn_Add_Click(object sender, EventArgs e)
        {
            //父结点
            int ID = int.Parse(Request.QueryString["ID"]);
            Model.SysManage.T_PUB_DICTIONARY detail = new Model.SysManage.T_PUB_DICTIONARY();

            BLL.SysManage.T_PUB_DICTIONARY option = new BLL.SysManage.T_PUB_DICTIONARY();

            detail.PARENT_ID = int.Parse(ddl_type.SelectedValue);
            detail.NAME = this.txtName.Text.Trim();
            

            if (this.txt_OrderID.Text != "")
            {
                detail.ORDER_ID = Convert.ToInt32(this.txt_OrderID.Text);
            }
            else
            {
                detail.ORDER_ID = 0;
            }



            detail.REMARK = this.txt_Other.Text;

            detail.FLAG = true;

            if (option.IsExistName(ID, this.txtName.Text.Trim()))
            {
                this.lbl_Message.Text = "此名称已存在";
                return;
            }
            else
            {
                this.lbl_Message.Text = "";
            }
            int flag = option.Add(detail);
            if (flag != 0)
            {

                if (this.CheckBox1.Checked == true)
                {
                    this.txtName.Text = "";
                    this.txt_OrderID.Text = (detail.ORDER_ID + 1).ToString();
                    this.txt_Other.Text = "";
                    Universal.JS.RunJS("alert(\"添加成功\");");
                    this.txtName.Focus();
                }
                else
                {
                    Universal.JS.RunJS("window.close();");
                }
            }
        }
        #endregion
    }
}